package com.qujia.station.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.qujia.common.constant.UserConstants;
import com.qujia.common.core.domain.entity.SysUser;
import com.qujia.common.core.domain.model.LoginUser;
import com.qujia.common.utils.SecurityUtils;
import com.qujia.common.utils.StringUtils;
import com.qujia.station.domain.AppUserSuperDetail;
import com.qujia.station.service.IAppUserSuperDetailService;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qujia.common.annotation.Log;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.enums.BusinessType;
import com.qujia.common.utils.poi.ExcelUtil;
import com.qujia.common.core.page.TableDataInfo;

/**
 * 【超级会员详情】Controller
 * 
 * @author qujia
 * @date 2021-11-30
 */
@RestController
@RequestMapping("/appusersuperdetail")
@Api(tags = "超级会员")
public class AppUserSuperDetailController extends BaseController
{
    @Autowired
    private IAppUserSuperDetailService appUserSuperDetailService;

    /**
     * 查询【超级会员详情】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppUserSuperDetail appUserSuperDetail)
    {
        startPage();
        if(appUserSuperDetail.getEndTime() != null){
            appUserSuperDetail.setEndTime(appUserSuperDetail.getEndTime()+" 23:59:59");
        }
        LoginUser user = SecurityUtils.getLoginUser();
        if (user != null) {
            SysUser sysUser = user.getUser();
            if (StringUtils.equalsAny(sysUser.getUserLevel(),UserConstants.LEVEL_TWO,UserConstants.LEVEL_THREE)) {
                // 油企、油站设置本油企id
                appUserSuperDetail.setEnterpriseId(sysUser.getEnterpriseId());
            }
        }
        List<AppUserSuperDetail> maps = appUserSuperDetailService.selectList(appUserSuperDetail);
        return getDataTable(maps);
    }

    /**
     * 导出【超级会员详情】列表
     */
    @Log(title = "【超级会员详情】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppUserSuperDetail appUserSuperDetail)
    {
        //List<AppUserSuperDetail> list = appUserSuperDetailService.selectAppUserSuperDetailList(appUserSuperDetail);
        if(appUserSuperDetail.getEndTime() != null){
            appUserSuperDetail.setEndTime(appUserSuperDetail.getEndTime()+" 23:59:59");
        }
        List<AppUserSuperDetail> list = appUserSuperDetailService.selectList(appUserSuperDetail);
        ExcelUtil<AppUserSuperDetail> util = new ExcelUtil<AppUserSuperDetail>(AppUserSuperDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取【超级会员详情】详细信息
     */
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(appUserSuperDetailService.selectAppUserSuperDetailById(userId));
    }

    /**
     * 新增【超级会员详情】
     */
    @Log(title = "【超级会员详情】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppUserSuperDetail appUserSuperDetail)
    {
        return toAjax(appUserSuperDetailService.insertAppUserSuperDetail(appUserSuperDetail));
    }

    /**
     * 修改【超级会员详情】
     */
    @Log(title = "【超级会员详情】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppUserSuperDetail appUserSuperDetail)
    {
        return toAjax(appUserSuperDetailService.updateAppUserSuperDetail(appUserSuperDetail));
    }

    /**
     * 删除【超级会员详情】
     */
    @Log(title = "【超级会员详情】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(appUserSuperDetailService.deleteAppUserSuperDetailByIds(userIds));
    }
}
